package top.dbpanda.cmsjpa.learn.rmi.proxy;


import java.lang.reflect.Proxy;

public class Test {
    public static void main(String[] args) {
        StaticProxy staticProxy = new StaticProxy();
        staticProxy.rent(200);
        RealSubject realSubject = new RealSubject();
        DynamicProxy dynamicProxy = new DynamicProxy(realSubject);
        Subject subject = (Subject) Proxy.newProxyInstance(dynamicProxy.getClass().getClassLoader(), realSubject.getClass().getInterfaces(), dynamicProxy);
        boolean rent = subject.rent(3000);
        System.out.println(rent ? "ok" : "error");
        RealSubject2 realSubject2 = new RealSubject2();
        DynamicProxy dynamicProxy2 = new DynamicProxy(realSubject2);
        Subject2 subject2 = (Subject2) Proxy.newProxyInstance(dynamicProxy2.getClass().getClassLoader(), realSubject2.getClass().getInterfaces(), dynamicProxy2);
        subject2.rentCar("宝马");

    }
}
